'''
@File    :   App_WriteDataById_0x2E_test.py
@Time    :   2022/8/25 13:31:28
@Author  :   YangLiang
@Version :   1.0
@Contact :   yangliang@chengtech.com
@License :   (C)Copyright 2022-2025
@Desc    :   None
'''

# here put the import lib
from gettext import find
from pytest_assume.plugin import assume

import pytest
import logging
import time
import requests
from sympy import I
# from sympy import assuming
from commDriver.TS_CAN import *
import allure
import sys
from collections.abc import Iterable

from sqlalchemy import false
sys.dont_write_bytecode = True

#NRC13
ReadDTCInfo_NRC13_phy = [   ([0x19],[0x7F,0x19,0x13]),                       
                            ([0x19,0x01],[0x7F,0x19,0x13]),
                            ([0x19,0x02],[0x7F,0x19,0x13]), 
                            ([0x19,0x04],[0x7F,0x19,0x13]), 
                            ([0x19,0x06],[0x7F,0x19,0x13]), 
                            ([0x19,0x01,0x01,0x02],[0x7F,0x19,0x13]),
                            ([0x19,0x02,0x01,0x02],[0x7F,0x19,0x13]),
                            ([0x19,0x04,0xAC],[0x7F,0x19,0x13]), 
                            ([0x19,0x04,0xAC,0xCE],[0x7F,0x19,0x13]), 
                            ([0x19,0x04,0xAC,0xCE,0x17],[0x7F,0x19,0x13]), 
                            ([0x19,0x04,0xAC,0xCE,0x17,0x01,0x02],[0x7F,0x19,0x13]), 
                            ([0x19,0x06,0xAC],[0x7F,0x19,0x13]), 
                            ([0x19,0x06,0xAC,0xCE],[0x7F,0x19,0x13]), 
                            ([0x19,0x06,0xAC,0xCE,0x17],[0x7F,0x19,0x13]), 
                            ([0x19,0x06,0xAC,0xCE,0x17,0x01,0x02],[0x7F,0x19,0x13]), 
                            ([0x19,0x0A,0x01],[0x7F,0x19,0x13])] 

#NRC12
ReadDTCInfo_NRC12_phy = [   ([0x19,0x08,0x01,0x02],[0x7F,0x19,0x12]),            
                            ([0x19,0x03,0x01,0x02,0x03,0x04],[0x7F,0x19,0x12]), 
                            ([0x19,0x05,0x01],[0x7F,0x19,0x12]), 
                            ([0x19,0x07,0x01,0x02],[0x7F,0x19,0x12]),
                            ([0x19,0x09,0x01,0x02,0x03],[0x7F,0x19,0x12]),
                            ([0x19,0x11,0x01,0x02,0x03],[0x7F,0x19,0x12]),
                            ([0x19,0x12,0x01,0x02,0x03],[0x7F,0x19,0x12]),
                            ([0x19,0x13],[0x7F,0x19,0x12])
                         ]

# NRC31
ReadDTCInfo_NRC31_phy = [   ([0x19,0x04,0x5C,0x1A,0x90,0x01],[0x7F,0x19,0x31]),          
                            ([0x19,0x04,0x11,0x22,0x33,0x01],[0x7F,0x19,0x31]),
                            ([0x19,0x04,0x5C,0x03,0x17,0x00],[0x7F,0x19,0x31]),
                            ([0x19,0x06,0x11,0x22,0x33,0x01],[0x7F,0x19,0x31]),
                            ([0x19,0x06,0x5C,0x03,0x17,0x00],[0x7F,0x19,0x31]),
                            ([0x19,0x06,0x12,0x22,0x33,0x01],[0x7F,0x19,0x31]),
                            ([0x19,0x06,0x58,0x03,0x17,0x00],[0x7F,0x19,0x31])]

#NRC13
ReadDTCInfo_NRC12_Priority = [  ([0x19,0x08],[0x7F,0x19,0x12]),            
                                ([0x19,0x03,0x01,0x02],[0x7F,0x19,0x12]), 
                                ([0x19,0x05],[0x7F,0x19,0x12]), 
                                ([0x19,0x07],[0x7F,0x19,0x12]),
                                ([0x19,0x11],[0x7F,0x19,0x12]),
                                ([0x19,0x12],[0x7F,0x19,0x12]),
                                ([0x19,0x13],[0x7F,0x19,0x12])
                            ]

ReadDTCInfo_NRC_no_resp_Fun = [ ([0x19,0x01],[0x7F,0x19,0x7F]), 
                                ([0x19,0x02],[0x7F,0x19,0x7F]), 
                                ([0x19,0x06],[0x7F,0x19,0x7F]),
                                ([0x19,0x05],[0x7F,0x19,0x7F]),          
                                ([0x19,0x0A],[0x7F,0x19,0x7F]), 
                                ([0x19,0x05],[0x7F,0x19,0x7F]), 
                                ([0x19,0x07],[0x7F,0x19,0x7F]), 
                                ([0x19,0x04,0x5C,0x1A,0x90,0x01],[0x7F,0x19,0x7F]),
                                ([0x19,0x04,0x11,0x22,0x33,0x01],[0x7F,0x19,0x7F]), 
                                ([0x19,0x04,0x5C,0x03,0x17,0x00],[0x7F,0x19,0x7F])
                            ]

#NRC12
ReadDTCInfo_NRC7F_phy = [   ([0x19, 0x01, 0x01], [0x7F, 0x19, 0x7F]),
                            ([0x19, 0x01, 0x08], [0x7F, 0x19, 0x7F]),
                            ([0x19, 0x01, 0x09], [0x7F, 0x19, 0x7F]),
                            ([0x19, 0x01, 0x0A], [0x7F, 0x19, 0x7F]),
                            ([0x19, 0x01, 0x0B], [0x7F, 0x19, 0x7F]),
                            ([0x19, 0x01, 0xFF], [0x7F, 0x19, 0x7F]),
                            ([0x19, 0x02, 0x01], [0x7F, 0x19, 0x7F]),
                            ([0x19, 0x02, 0x08], [0x7F, 0x19, 0x7F]),
                            ([0x19, 0x02, 0x09], [0x7F, 0x19, 0x7F]),
                            ([0x19, 0x02, 0x0A], [0x7F, 0x19, 0x7F]),
                            ([0x19, 0x02, 0x0B], [0x7F, 0x19, 0x7F]),
                            ([0x19, 0x02, 0xFF], [0x7F, 0x19, 0x7F]),
                            ([0x19, 0x04, 0xAC,0xD1,0x78,0x01], [0x7F, 0x19, 0x7F]),
                            ([0x19, 0x04, 0xAC,0xD1,0x78,0x02], [0x7F, 0x19, 0x7F]),
                            ([0x19, 0x06, 0xAC,0xD2,0x78,0x01], [0x7F, 0x19, 0x7F]),
                            ([0x19, 0x06, 0xAC,0xD2,0x78,0x02], [0x7F, 0x19, 0x7F]),
                         ]

class Test_ReadDTCInfomation_NRC_phy(object):

    '''NRC13'''
    ids = ["Request {0}".format(binascii.b2a_hex(bytearray(req), ' '), resp) for req, resp in ReadDTCInfo_NRC13_phy]
    @allure.severity('normal')
    @allure.story('Test NRC13 of read dtc information service 0x19')
    @allure.description('Test NRC13 of read dtc information service 0x19 in default session with physical addressing')
    @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp', ReadDTCInfo_NRC13_phy, ids=ids)
    def test_reportNumberOfDTC_NRC13_default_Phy(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 1, iStep, False, 'UDS', 'noClearFault')

    @allure.severity('normal')
    @allure.story('Test NRC13 of read dtc information service 0x19')
    @allure.description('Test NRC13 of read dtc information service 0x19 in extended session with physical addressing')
    @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp', ReadDTCInfo_NRC13_phy, ids=ids)
    def test_reportNumberOfDTC_NRC13_Extended_Phy(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep, False, 'UDS', 'noClearFault')



    '''NRC12'''
    ids = ["Request {0}".format(binascii.b2a_hex(bytearray(req), ' '), resp) for req, resp in ReadDTCInfo_NRC12_phy]
    @allure.severity('normal')
    @allure.story('Test NRC12 of read dtc information service 0x19')
    @allure.description('Test NRC12 of read dtc information service 0x19 in default session with physical addressing')
    @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp', ReadDTCInfo_NRC12_phy, ids=ids)
    def test_reportNumberOfDTC_NRC12_default_Phy(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 1, iStep, False, 'UDS', 'noClearFault')

    @allure.severity('normal')
    @allure.story('Test NRC12 of read dtc information service 0x19')
    @allure.description('Test NRC12 of read dtc information service 0x19 in extended session with physical addressing')
    @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp', ReadDTCInfo_NRC12_phy, ids=ids)
    def test_reportNumberOfDTC_NRC12_Extended_Phy(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep, False, 'UDS', 'noClearFault')


    '''NRC31'''
    ids = ["Request {0}".format(binascii.b2a_hex(bytearray(req), ' '), resp) for req, resp in ReadDTCInfo_NRC31_phy]
    @allure.severity('normal')
    @allure.story('Test NRC31 of read dtc information service 0x19')
    @allure.description('Test NRC31 of read dtc information service 0x19 in default session with physical addressing')
    @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp', ReadDTCInfo_NRC31_phy, ids=ids)
    def test_reportNumberOfDTC_NRC31_default_Phy(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 1, iStep, False, 'UDS', 'noClearFault')

    @allure.severity('normal')
    @allure.story('Test NRC31 of read dtc information service 0x19')
    @allure.description('Test NRC31 of read dtc information service 0x19 in extended session with physical addressing')
    @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp', ReadDTCInfo_NRC31_phy, ids=ids)
    def test_reportNumberOfDTC_NRC31_Extended_Phy(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep, False, 'UDS', 'noClearFault')



    '''NRC13_Priority'''
    ids = ["Request {0}".format(binascii.b2a_hex(bytearray(req), ' '), resp) for req, resp in ReadDTCInfo_NRC12_Priority]
    @allure.severity('normal')
    @allure.story('Test NRC13 Priority of read dtc information service 0x19')
    @allure.description('Test NRC13 Priority of read dtc information service 0x19 in default session with physical addressing')
    @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp', ReadDTCInfo_NRC12_Priority, ids=ids)
    def test_reportNumberOfDTC_NRC12_priority_default_Phy(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 1, iStep, False, 'UDS', 'noClearFault')

    @allure.severity('normal')
    @allure.story('Test NRC13 Priority of read dtc information service 0x19')
    @allure.description('Test NRC13 Priority of read dtc information service 0x19 in extended session with physical addressing')
    @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp', ReadDTCInfo_NRC12_Priority, ids=ids)
    def test_reportNumberOfDTC_NRC12_priority_Extended_Phy(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep, False, 'UDS', 'noClearFault')


    '''NRC7F'''
    ids = ["Request {0}".format(binascii.b2a_hex(bytearray(req), ' '), resp) for req, resp in ReadDTCInfo_NRC7F_phy]
    @allure.severity('normal')
    @allure.story('Test NRC7F of read dtc information service 0x19')
    @allure.description('Test NRC7F of read dtc information service 0x19 in default session with physical addressing')
    @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp', ReadDTCInfo_NRC7F_phy, ids=ids)
    def test_reportNumberOfDTC_NRC7F_Programming_Phy(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False, 'UDS', 'noClearFault')



    # '''NRC no resp Fun'''
    # ids = ["Request {0}".format(binascii.b2a_hex(bytearray(req), ' '), resp) for req, resp in ReadDTCInfo_NRC_no_resp_Fun]
    # @allure.severity('normal')
    # @allure.story('Test NRC no response of read dtc information service 0x19')
    # @allure.description('Test NRC no response of read dtc information service 0x19 in default session with function addressing')
    # @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    # @pytest.mark.parametrize('req,resp', ReadDTCInfo_NRC_no_resp_Fun, ids=ids)
    # def test_reportNumberOfDTC_NRC_No_Resp_default_Fun(self, action, Driver, req, resp):
    #     iStep = 1
    #     iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 1, iStep, False, 'UDSFun', 'noClearFault')

    # @allure.severity('normal')
    # @allure.story('Test NRC no response of read dtc information service 0x19')
    # @allure.description('Test NRC no response of read dtc information service 0x19 in extended session with function addressing')
    # @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    # @pytest.mark.parametrize('req,resp', ReadDTCInfo_NRC_no_resp_Fun, ids=ids)
    # def test_reportNumberOfDTC_NRC_No_Resp_extended_Fun(self, action, Driver, req, resp):
    #     iStep = 1
    #     iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep, False, 'UDSFun', 'noClearFault')


class Test_ReadDTCInfomation_NRC_fun(object):

    '''NRC13'''
    ids = ["Request {0}".format(binascii.b2a_hex(bytearray(req), ' '), resp) for req, resp in ReadDTCInfo_NRC13_phy]
    @allure.severity('normal')
    @allure.story('Test NRC13 of read dtc information service 0x19')
    @allure.description('Test NRC13 of read dtc information service 0x19 in default session with functional addressing')
    @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp', ReadDTCInfo_NRC13_phy, ids=ids)
    def test_reportNumberOfDTC_NRC13_default_Fun(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 1, iStep, False, 'UDSFun', 'noClearFault')

    @allure.severity('normal')
    @allure.story('Test NRC13 of read dtc information service 0x19')
    @allure.description('Test NRC13 of read dtc information service 0x19 in extended session with functional addressing')
    @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp', ReadDTCInfo_NRC13_phy, ids=ids)
    def test_reportNumberOfDTC_NRC13_Extended_Fun(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep, False, 'UDSFun', 'noClearFault')



    '''NRC12'''
    ids = ["Request {0}".format(binascii.b2a_hex(bytearray(req), ' '), resp) for req, resp in ReadDTCInfo_NRC12_phy]
    @allure.severity('normal')
    @allure.story('Test NRC12 of read dtc information service 0x19')
    @allure.description('Test NRC12 of read dtc information service 0x19 in default session with functional addressing')
    @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp', ReadDTCInfo_NRC12_phy, ids=ids)
    def test_reportNumberOfDTC_NRC12_default_Fun(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 1, iStep, False, 'UDSFun', 'noClearFault')

    @allure.severity('normal')
    @allure.story('Test NRC12 of read dtc information service 0x19')
    @allure.description('Test NRC12 of read dtc information service 0x19 in extended session with functional addressing')
    @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp', ReadDTCInfo_NRC12_phy, ids=ids)
    def test_reportNumberOfDTC_NRC12_Extended_Fun(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep, False, 'UDSFun', 'noClearFault')


    '''NRC31'''
    ids = ["Request {0}".format(binascii.b2a_hex(bytearray(req), ' '), resp) for req, resp in ReadDTCInfo_NRC31_phy]
    @allure.severity('normal')
    @allure.story('Test NRC31 of read dtc information service 0x19')
    @allure.description('Test NRC31 of read dtc information service 0x19 in default session with functional addressing')
    @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp', ReadDTCInfo_NRC31_phy, ids=ids)
    def test_reportNumberOfDTC_NRC31_default_Fun(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 1, iStep, False, 'UDSFun', 'noClearFault')

    @allure.severity('normal')
    @allure.story('Test NRC31 of read dtc information service 0x19')
    @allure.description('Test NRC31 of read dtc information service 0x19 in extended session with functional addressing')
    @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp', ReadDTCInfo_NRC31_phy, ids=ids)
    def test_reportNumberOfDTC_NRC31_Extended_Fun(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep, False, 'UDSFun', 'noClearFault')



    '''NRC13_Priority'''
    ids = ["Request {0}".format(binascii.b2a_hex(bytearray(req), ' '), resp) for req, resp in ReadDTCInfo_NRC12_Priority]
    @allure.severity('normal')
    @allure.story('Test NRC13 Priority of read dtc information service 0x19')
    @allure.description('Test NRC13 Priority of read dtc information service 0x19 in default session with functional addressing')
    @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp', ReadDTCInfo_NRC12_Priority, ids=ids)
    def test_reportNumberOfDTC_NRC12_priority_default_Fun(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 1, iStep, False, 'UDSFun', 'noClearFault')

    @allure.severity('normal')
    @allure.story('Test NRC13 Priority of read dtc information service 0x19')
    @allure.description('Test NRC13 Priority of read dtc information service 0x19 in extended session with functional addressing')
    @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp', ReadDTCInfo_NRC12_Priority, ids=ids)
    def test_reportNumberOfDTC_NRC12_priority_Extended_Fun(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep, False, 'UDSFun', 'noClearFault')


    '''NRC7F'''
    ids = ["Request {0}".format(binascii.b2a_hex(bytearray(req), ' '), resp) for req, resp in ReadDTCInfo_NRC7F_phy]
    @allure.severity('normal')
    @allure.story('Test NRC7F of read dtc information service 0x19')
    @allure.description('Test NRC7F of read dtc information service 0x19 in default session with functional addressing')
    @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp', ReadDTCInfo_NRC7F_phy, ids=ids)
    def test_reportNumberOfDTC_NRC7F_Programming_Fun(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False, 'UDSFun', 'noClearFault')



    # '''NRC no resp Fun'''
    # ids = ["Request {0}".format(binascii.b2a_hex(bytearray(req), ' '), resp) for req, resp in ReadDTCInfo_NRC_no_resp_Fun]
    # @allure.severity('normal')
    # @allure.story('Test NRC no response of read dtc information service 0x19')
    # @allure.description('Test NRC no response of read dtc information service 0x19 in default session with functional addressing')
    # @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    # @pytest.mark.parametrize('req,resp', ReadDTCInfo_NRC_no_resp_Fun, ids=ids)
    # def test_reportNumberOfDTC_NRC_No_Resp_default_Fun(self, action, Driver, req, resp):
    #     iStep = 1
    #     iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 1, iStep, False, 'UDSFun', 'noClearFault')

    # @allure.severity('normal')
    # @allure.story('Test NRC no response of read dtc information service 0x19')
    # @allure.description('Test NRC no response of read dtc information service 0x19 in extended session with functional addressing')
    # @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    # @pytest.mark.parametrize('req,resp', ReadDTCInfo_NRC_no_resp_Fun, ids=ids)
    # def test_reportNumberOfDTC_NRC_No_Resp_extended_Fun(self, action, Driver, req, resp):
    #     iStep = 1
    #     iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep, False, 'UDSFun', 'noClearFault')